<%@page import="java.io.OutputStream"%>
<%@page import="java.util.Random"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="../css/bsp.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<%!
public Integer getRendomInt(){
	Integer i = new Double(Math.random()*100).intValue();
	return i;
}

public Integer inc(Integer counter,HttpServletRequest request )throws Exception{
	try{
		counter = Integer.parseInt(request.getSession().getAttribute("counter").toString());
		}catch (Exception e){
			counter = null;
			
		}
		if(counter == null){
			counter = new Integer(0);
			request.getSession().setAttribute("counter",counter);
			return counter;
		}else{
			counter += 1;
			request.getSession().setAttribute("counter",counter);
			return counter;
		}
}

%>

</head>
<body>
<div id="wrapper">


<div id="outheader"><div id="inheader">
<h1>NumberGuess</h1>
</div></div>


 
 <div id="outleftcolumnbig"><div id="inleftcolumn">
<%
Integer counter = null;
counter = inc(counter,request);
Integer guess;
try{
 guess = Integer.parseInt(request.getParameter("guess")); 
}catch (Exception e){
	guess = null;
}
if(guess == null){
	guess = 0;
}
Integer number = (Integer)request.getSession().getAttribute("number");
if (number == null){
	number = getRendomInt();
	request.getSession().setAttribute("number",number);
}

if (guess < number){
	out.write("deine  Zahl ist zu klein      "+ "count: " + counter);
}else if(guess > number){
	out.write("deine  Zahl ist zu gross      "+ "count: " + counter);
}else{
	out.write("<p size:100px>TREFFER</p>");
	request.getSession().removeAttribute("counter");
	request.getSession().removeAttribute("number");
}




%>

<p id=100> Geben sie eine Zahl von 1-100 ein </p>
<form action="NumberGuess.jsp" method="post">
<input type="text" name="guess"/>
<input type="submit" Value="Senden"/>
</form>

</div></div>

</div>


</body>
</html>